﻿
<div class="ld-tabs">
    <ul>
        <li class="k-state-active">客户分类</li>
    </ul>
    <div>
        <div class="k-block divToolbar">
            <button class="k-button" onclick="CreateNewCategory()"><span class="k-icon k-i-plus"></span><span>添加新分类</span></button>
        </div>
        <div id="grid_category" style="text-align: center"></div>
    </div>
</div>
<script class="init">
    LocatedMenu("成员管理", "客户分类");
</script>
<script class="grid_category_columns">
    var categoryFields = [{
        title: "#",
        field: "ID",
        width: 50
    }, {
        title: "分类名称",
        field: "CategoryName",
        width: 200
    }, {
        title: "操作",
        template: "#=GetOperations(ID)#",
        attributes: { style: "text-align:left" }
    }];

    function GetOperations(id) {
        var html = "<button class='k-button' onclick=\"EditCategory(" + id + ")\"><span class='k-icon k-i-pencil'></span><span>修改</span></button>";
        html += "<button class='k-button' onclick=\"DeleteCategory(" + id + ")\"><span class='k-icon k-i-close'></span><span>删除</span></button>";
        return html;
    }

    function EditCategory(id) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "修改分类信息" });
            wndGeneralEdit.refresh({ url: "/Members/CustomerCategory/Edit/" + id });
            wndGeneralEdit.open();
        }
    }

    function DeleteCategory(id) {
        if (confirm("真的要删除这个分类吗?")) {
            Whale.Remote.Operation({
                url: "/Members/CustomerCategory/DeleteCategory",
                parameters: { categoryID: id },
                success: function (result) {
                    if ($("#grid_category").length > 0)
                        $("#grid_category").data("kendoGrid").dataSource.read();
                },
                error: function (msg) {
                    wndGeneralInformation.content(msg).open();
                }
            });
        }
    }


</script>

<script class="grid_config">
    $(function () {
        $("#grid_category").kendoGrid({
            columns: categoryFields,
            dataSource: Whale.dataSource({
                url: "/Members/CustomerCategory/GetCategories",
                pageSize: 20

            }),
            pageable: {
                messages: {
                    empty: "暂无数据"
                }
            },
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            }
        });
    });

    function CreateNewCategory() {
        wndGeneralEdit.setOptions({ title: "添加新的分类" });
        wndGeneralEdit.refresh({ url: "/Members/CustomerCategory/Edit" });
        wndGeneralEdit.open();
    }

    //function FilterClass() {
    //    $("#grid_category").data("kendoGrid").dataSource.read();
    //}
</script>